﻿#pragma once

#include <EASTL/unordered_map.h>
#include <EASTL/vector.h>
#include <EASTL/string_view.h>
#include <static_string.h>
#include <xml_reader.h>
#include <memory>
#include <game/config/config_info.h>

namespace ifire::game {
class ConfigManager;
constexpr int AVATAR_NONE_ID = -1;
constexpr int AVATAR_ROOT_ID = 0;

struct AvatarBoneID {
  int index;       // 索引
  ikit::sstr name; // 名称
  bool fix_direction; // 是否修复骨骼方向

  AvatarBoneID(int index, ikit::sstr name);
  AvatarBoneID(const ikit::XmlNode& node, int index);
};

class AvatarGroup : public ConfigInfo {
public:
  AvatarGroup(ConfigManager* manager, const ikit::XmlNode& node);
  AvatarGroup(const AvatarGroup& lhs) = delete;
  AvatarGroup& operator=(const AvatarGroup& lhs) = delete;
  ~AvatarGroup() = default;

  // 通过名称获得ID
  int GetID(ikit::sstr name) const;
  // 检查是否是FootFix的项目
  bool IsFootFix(int avatar_id) const;

  // ------
  // 属性访问
  // ------
  inline const AvatarBoneID& Get(int index) const { return items_[index]; }
  inline size_t size() const { return items_.size(); }

public:
  // 名称，直接访问
  ikit::sstr name;  
  // 核心骨骼的ID，如果不配置，那么就是-1。（Root永远是0）
  int hips_id;
  int spine_id;
  int neck_id;
  int head_id;
  int left_foot_id;
  int right_foot_id;
  int left_toes_id;
  int right_toes_id;
  int left_hand_id;
  int right_hand_id;

private:
  eastl::vector<AvatarBoneID> items_;
  eastl::unordered_map<size_t, int> map_;
};

using AvatarGroupPtr = std::unique_ptr<AvatarGroup>;



} // namespace ifire::game